package tour.spring.bc.component;

import java.util.Calendar;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import tour.spring.bc.dao.TourDao;
import tour.spring.bc.model.Tour;


@Component
public class LastMinuteScheduler {
	
	@Autowired
	TourDao tourDao;
	@Autowired
	JmsTemplate jmsTemplate;

	@Scheduled(fixedDelay = 6000)
	public void process(){
		jmsTemplate.convertAndSend("----->sdfsdfasdfasdf");
		
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DAY_OF_WEEK, 7);
		
		List<Tour> tours = tourDao.loadAll();
		for (Tour tour : tours) {
			if(c.getTime().after(tour.getDateFrom()))
				tour.setBasePrice(tour.getBasePrice()-tour.getBasePrice()/10);
		}
		
	}

	public void setTourDao(TourDao tourDao) {
		this.tourDao = tourDao;
	}
	
}
